<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        include "includes/ketnoi.php";
        $result = $conn->query("SELECT * FROM users");
        ?>
        <table border="1">
            <tr>
                <td colspan="5" class="title">ĐỔI MẬT KHẨU
                </td>
            </tr>
            <tr>

                <?php
                include "includes/ketnoi.php";
                $result1 = $conn->query("SELECT password FROM users WHERE id='1'");

                if (isset($_POST['B1'])) {
                    
                    $oldpass= md5(addslashes($_POST['oldpass']));       
                    $pass = md5(addslashes($_POST['pass']));
                    
                    if ($_POST['pass'] == "" || $_POST['repass'] == "" || $_POST['oldpass'] == "") {
                        echo"Nhap du thong tin!!!";
                    } else {
                        if ($_POST['pass'] == $_POST['repass']) {
                            if ($result1 != $oldpass) {
                                $sqlx = $conn->query("UPDATE `users` SET `password` = '" . $pass . "' WHERE `id` = '1';");                               
                                if ($sqlx)
                                    echo "(Đã đổi pass) ";
                                else
                                    echo "(Chưa đổi pass) ";
                            } else {
                                echo"Trung pass cu";
                            }
                        } else {
                            echo"Nhap Repass sai !!!";
                        }
                    }
                }
                ?>
            <form method='POST' action=''>
                <table border='1' width='100%' id='table1' cellspacing='0' cellpadding='0' style='border-collapse: collapse' bordercolor='#C0C0C0'>
                    <tr>
                        <td>Pass cu:</td>
                        <td><input type='password' name='oldpass' size='20'></td>
                    </tr>          
                    <tr>
                        <td>Pass mới:</td>
                        <td><input type='password' name='pass' size='20'></td>
                    </tr>               
                    <tr>
                        <td>Nhap lại Pass mới:</td>
                        <td><input type='password' name='repass' size='20'></td>
                    </tr>                        
                </table>
                <p align='center'><input type='submit' value='Sửa' name='B1'><input type='reset' value='Tro ve' name='B2'></p>
            </form>
    </body>
</html>
